package com.langhang.service.impl;

import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.langhang.SpecSearch.SpecS;
import com.langhang.entity.TbSpecification;
import com.langhang.entity.TbSpecificationExample;
import com.langhang.entity.TbSpecificationOption;
import com.langhang.mapper.TbSpecificationMapper;
import com.langhang.mapper.TbSpecificationOptionMapper;
import com.langhang.service.TbSpecificationService;
import com.langhang.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TbSpecificationServiceImpl implements TbSpecificationService {
    @Autowired
    private TbSpecificationMapper tbSpecificationMapper;


    @Override
    public List<TbSpecification> findCLASS() {
        return tbSpecificationMapper.selectByExample(null);
    }
    @Override
    public PageResult<TbSpecification> search(Integer page, Integer pageSize, SpecS specs) {

        PageHelper.startPage(page,pageSize);
        TbSpecificationExample example = new TbSpecificationExample();
        TbSpecificationExample.Criteria criteria = example.createCriteria();
        if (StrUtil.isNotBlank(specs.getSpecname())) {
            criteria.andSpecNameLike("%" + specs.getSpecname() + "%");
        }
        List<TbSpecification> tbspecs = tbSpecificationMapper.selectByExample(example);
        Page<TbSpecification> tbspecPage = (Page<TbSpecification>) tbspecs;
        return new PageResult<>(tbspecPage.getResult(),tbspecPage.getTotal());
    }

    @Override
    public boolean save(TbSpecification tbspec) {
        return tbSpecificationMapper.insert(tbspec) > 0;
    }


}